﻿import os from 'os';

function getLocalIPs(): string[] {
  const interfaces = os.networkInterfaces();
  const addresses: string[] = [];

  // 设置要排除的虚拟机接口名称前缀
  const excludePrefixes = ['vboxnet', 'vmnet', 'VMware', 'VirtualBox', 'enp0s'];

  for (const interfaceName in interfaces) {
    // 检查接口名称是否以指定前缀开始
    if (excludePrefixes.some(prefix => interfaceName.startsWith(prefix))) {
      continue;
    }
    const interfaceInfo = interfaces[interfaceName];
    if (interfaceInfo) {
      for (const interfaceDetail of interfaceInfo) {
        if (interfaceDetail.family === 'IPv4' && !interfaceDetail.internal) {
          addresses.push(interfaceDetail.address);
        }
      }
    }
  }

  return addresses;
}

const localIPs = getLocalIPs();
console.log('本机的IP地址:', localIPs);
